<?php

class AdminFileController extends AdminController
{
  use ApiTrait;

  public function imageAction()
  {
    //图片上传
    $type = $this->req->getPostTrim('type');
    $thumbs = ['adminhead' =>[ 'ext' => '150x150','size' => [150, 150]]];
    if ($this->req->isAjax() && $this->req->isPost() && in_array($type, [ 'adminhead', 'storeitem', 'gift'])) {
     $fileModel = $this->getModel('file');
     $thumb = $thumbs[$type] ?? [];
     $thumbSizes = [];
     $uploadResult = uploadImage($type,  null, $thumb ? [$thumb['ext'] => $thumb['size']]: [], 'image');
     $uploadResult['url'] = $thumb ? $uploadResult['thumb'][$thumb['ext']] : $uploadResult['url'];
     if ($type == 'adminhead') { $uploadResult['url'] = $uploadResult['thumb'][$thumb['ext']]; }
     return $this->okReturn($uploadResult);
   }
  }
}
